package hari2.latihan;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

public class Pengirim {
	
	private PrintWriter output;
	private Socket socket;
	
	public Pengirim(String alamatTujuan, Integer portTujuan) {
		try {
			socket = new Socket(alamatTujuan, portTujuan);
			output = new PrintWriter(socket.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void kirim(String pesan) {
		output.print(pesan);
		output.flush();
	}
	
	public void disconnect() {
		output.close();
		try {
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
